﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace ComicsEditor
{
    public class TextSelectInstrument : Instrument
    {
        private Text selectedText;

        public TextSelectInstrument()
        {
        }

        public override bool Activate(Point point, out Point offset)
        {
            offset = Point.Empty;
            foreach (Text text in pageInfo.Texts)
                if (text.Test(point))
                {
                    pageInfo.TextSelect(text);
                    selectedText = text;
                    return true;
                }
            pageInfo.TextSelect(null);
            return false;
        }

        public override void Drag(Point newPoint, Point offset, Point deltaActivate, Point deltaMove)
        {
            if (selectedText != null)
            {
                selectedText.Position.Offset(deltaMove);
                Page.Changed = true;
            }
        }

        public override void Deactivate()
        {
            selectedText = null;
        }
    }
}
